﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Random = UnityEngine.Random;

public static class Vector3Extension
{
    public static Vector3 SetX(this Vector3 self, float x) => new Vector3(x, self.y, self.z);
    public static Vector3 SetY(this Vector3 self, float y) => new Vector3(self.x, y, self.z);
    public static Vector3 SetZ(this Vector3 self, float z) => new Vector3(self.x, self.y, z);

    public static Vector2 GetXY(this Vector3 self) => (Vector2)self;
    public static Vector2 GetXZ(this Vector3 self) => new Vector2(self.x, self.z);
    public static Vector2 GetYZ(this Vector3 self) => new Vector2(self.y, self.z);

    public static Vector3 RandomSphericalPoint(this Vector3 center, float radius,float coverage = 0.5f)
    {
        float theta = Random.Range(0f, coverage * Mathf.PI); // [0, π]
        float phi = Random.Range(0f, 2 * Mathf.PI); // [0, 2π]

        float x = (Mathf.Sin(theta) * Mathf.Cos(phi)) * radius;
        float z = (Mathf.Sin(theta) * Mathf.Sin(phi)) * radius;
        float y = Mathf.Cos(theta) * radius;

        Vector3 startPos = new Vector3(x, y, z) + center;

        return startPos;
    }

}
